/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.car;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.car.CarRepair;
import com.unis.service.car.CarRepairService;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-01-11
 */
@Controller
@RequestMapping("/carrepair")
public class CarRepairController {

    private CarRepairService carrepairService;

    /****************************************
     * Insert a instace of CarRepair
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertCarRepair(@RequestBody CarRepair carrepair) throws Exception {
        carrepair.setStatmentId("CarRepair.insert");
        String status = "failure";
        carrepairService.insert(carrepair);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of CarRepair
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody CarRepair carrepair) throws Exception {
        carrepair.setStatmentId("CarRepair.update");
        String status = "failure";
        carrepairService.update(carrepair);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of CarRepair
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody CarRepair carrepair) throws Exception {
        carrepair.setStatmentId("CarRepair.delete");
        String status = "failure";
        carrepairService.batchDelete(carrepair);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of CarRepair
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        CarRepair carrepair = new CarRepair();
        carrepair.setStatmentId("CarRepair.queryAsList");
        BeanUtils.populate(carrepair, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(carrepair, pageMap);
        List<BaseModel> carrepairList = carrepairService.queryAsList(carrepair);
        Map<String, Object> renderMap = GridUIMapper.render(carrepair, carrepairList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of CarRepair
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody CarRepair carrepair) throws Exception {
        carrepair.setStatmentId("CarRepair.queryAsObject");
        return carrepairService.queryAsObject(carrepair);
    }

    @RequestMapping("/page")
    public String forword() {
        return "car/carrepairList";
    }

    @Resource
    public void setCarRepairService(CarRepairService carrepairService) {
        this.carrepairService = carrepairService;
    }
}
